﻿using Gmail.Presenters.Events;
using Gmail.Model;
using System;
namespace Gmail.Presenters
{
    // Change IDefaultView to your desired View interface.
    public class LoginPresenter 
    {
        ILoginView View;
        public LoginPresenter(ILoginView View)
        {
            this.View = View;
            this.View.LoginSubmitEvent += new LoginSubmitEventHandler(View_LoginSubmitEvent);
        }

        bool View_LoginSubmitEvent(object sender, LoginSubmitEventArgs e)
        {
            Connector Connector = Connector.GetInstance(e.Username, e.Password);
            
            if (Connector.Connect())
            {
                if (e.RememberMe)
                {

                }
                App.ShowEmail(_Filename,_DisplayFilename,Connector);
                return true;
            }
            return false;

        }

        private String _Filename;
        private String _DisplayFilename;
        public void ShowForm(String Filename,String DisplayFilename){
            _Filename = Filename;
            _DisplayFilename = DisplayFilename;
            View.FormInit();
        }

        public void Relogin(String Filename, String DisplayFilename)
        {
            _Filename = Filename;
            _DisplayFilename = DisplayFilename;
            View.FormInit(true);
        }


        
    }
}
